package com.example.qiaoruian.shequ.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.qiaoruian.shequ.R;
import com.example.qiaoruian.shequ.bean.User;

import java.util.List;


public class GridViewGroupAdapter extends BaseAdapter {
    private List<User> list;
    private Context context;
    private LayoutInflater inflater;


    public GridViewGroupAdapter(List<User> list, Context context) {
        this.list = list;
        this.context = context;

        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = new ViewHolder();

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.gridadapter_group,null);
            holder.mcircle = (ImageView) convertView.findViewById(R.id.iv_gd);
            holder.ll = (LinearLayout) convertView.findViewById(R.id.ll);
            holder.tv_llqitem = (TextView) convertView.findViewById(R.id.tv_gd);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();
        User user = list.get(position);
        holder.tv_llqitem.setText(user.getName());
        holder.mcircle.setImageResource(user.getRes());
         int re=user.getOtherres();
        if (re!=0){
              holder.ll.setBackgroundResource(re);
        }
        return convertView;
    }

    private class ViewHolder {
        private LinearLayout ll ;
        private ImageView mcircle;
        private TextView tv_llqitem;
    }
}
